define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'base/school/index',
                    add_url: 'base/school/add',
                    edit_url: 'base/school/edit',
                    del_url: 'base/school/del',
                    multi_url: 'base/school/multi',
                    table: 'base_school',
                }
            });

            var table = $("#table");
             table.on('post-common-search.bs.table', function (event, table) {
                var form = $("form", table.$commonsearch);
                $("input[name='book_id']", form).addClass("selectpage").data("source", "base/book/index").data("primaryKey", "id").data("field", "name",'id').data("orderBy", "id desc");
                Form.events.cxselect(form);
                Form.events.selectpage(form);
            });
            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'weigh',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'weigh', title: __('Weigh')},
                        {field: 'name', title: __('Name')},
                        {field: 'book_text', title: __('Book_id')},
                      {field: 'book_id', title: __('Book_id'),operate:"FINDINSET", visible: false,formatter: Table.api.formatter.search},
                        {field: 'type', title: __('Type'), searchList: {"1":__('Type 1'),"2":__('Type 2'),"3":__('Type 3')}, formatter: Table.api.formatter.normal},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        // {field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                         {field: 'publish_text', title: __('Publish')},
                        //操作栏,默认有编辑、删除或排序按钮,可自定义配置buttons来扩展按钮
                        {
                            field: 'title',
                            width: "120px",
                            title: __('信息管理'),
                            table: table,
                            events: Table.api.events.operate,
                            buttons: [
                                {
                                  name: 'detail',
                                  title: __('班级信息'),
                                  extend:"data-area='[\"70%\",\"70%\"]'",
                                  classname: 'btn btn-xs btn-primary btn-dialog',
                                  icon: 'fa fa-bank',
                                  url: 'base/school_class/index',
                               
                            },
                              
                            ],
                            formatter: Table.api.formatter.buttons
                        },
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});